import $ from '../common';
Page({
  data: {
    img:'https://sxzimgs.oss-cn-shanghai.aliyuncs.com/yingxiao/page/f91e5fe4-cf2e-11e7-9713-44032ca554a5.png',
    sexlist:['男','女'],
    sexparamslist:['male','female'],
    avatar:'',
    name:'',
    sexparam:'',
    shcool:'',
    class:'',

    sexidx:0,
    noimg:$.noImage
  },
  onLoad(e) {
    this.setData({
      zonecode: wx.getStorageSync('addresscode') || '',
      uuid:e.uuid,
      campus_uuid:e.campus_uuid,
      type:e.type
    })    
    this.getinfo()
    // 497066369@qq.com lzy497066369
  },
  onShow() {

  },
  godelete(){
    $.post('/student/uncertify/remove',{
      zonecode:this.data.zonecode,
      student_uuid:this.data.uuid
    },res=>{
      $.parent().getinfo()
      $.navigateBack()
    })
  },
  getinfo(){
    let url='/student/uncertified/detail'
    if(this.data.campus_uuid) url='/student/certified/detail'
    $.get(url,{
      zonecode:this.data.zonecode,
      student_uuid:this.data.uuid,
      campus_uuid:this.data.campus_uuid
    },res=>{
      let a =this.data.sexparamslist.indexOf(res.student.gender?res.student.gender:'male')
      res.student.gender
      this.setData({
        info:res.student,
        sexidx:a,
        avatar:'',
        name:'',
        sexparam:'',
        shcool:'',
        class:'',  
      })
    })
  },
  bindMultiPickerChange(e){
    this.setData({
      sexidx:e.detail.value,
      sexparam:this.data.sexparamslist[e.detail.value]
    })
    this.updata()
  },
  updata(){
    let url='/student/uncertified/update'
    if(this.data.type=='certify') url='/student/certified/update'
    let obj={
      campus_uuid:this.data.campus_uuid,
      student_uuid:this.data.uuid,
      avatar:this.data.avatar||'',
      gender:this.data.sexparam||''
    }
    $.post(url,obj,res=>{
      this.getinfo()
    })
  },
  addavatar(){
    wx.chooseImage({
      count:1,
      sizeType: "compressed",
      success: (res) => {
        var newList = res.tempFilePaths
        $.uploadFileList('/image/upload/oss', {
            fileList: newList,
            prefix: "keday/"
          },
          (res) => {
            this.setData({
              avatar: res
            })
            this.updata()
          },
          (err) => {
            console.log('上传失败:', err)
          }
        )
      }
    })
  },
  handle(e){
    const {key,tit,value='',inputtype}=e.currentTarget.dataset
    const{uuid,campus_uuid='',type}=this.data
    let url=this.data.type=='certify'?'/student/certified/update':'/student/uncertified/update'
    if(key=='name'&&this.data.type=='certify')return
    let obj={
      key,tit,value,campus_uuid,student_uuid:uuid,type,inputtype,url
    }
    $.navigateTo(`/address/childupdata?info=${JSON.stringify(obj)}`)
  },
  chooseschool(){
    $.navigateTo('/address/addchildu')
  }
})